import json
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage  
from django.shortcuts import render, HttpResponse
from django.http import JsonResponse
from data.models import Data

# Create your views here.
def list(request):
    start = int(request.GET.get('start'))
    page = int(request.GET.get('page'))
    deviceId = request.GET.get('deviceId')
    data_list  = Data.objects.filter(deviceId=deviceId).order_by('-date')[start:page]
    res_data = []
    for data in data_list:
        item = {
            'id': data.id,
            'cardNum': data.cardNum,
            'deviceId': data.deviceId,
            'date': data.date
        }
        res_data.append(item)
    return JsonResponse({"list": res_data})


